|
|
|
|
|
|
|
Setting Up the Button's Events |
|
|
|
|
|
|
|
|
You also can use the ActiveX Control Interface Wizard to create the events for the Color Button control. You can do so at the same time you create the properties, or you can run the wizard again. Remember to map the Click, GotFocus, MouseDown, and MouseUp events to the corresponding events in the UserControl. (Refer to the section "Mapping Properties" earlier in the chapter.) |
|
|
|
|
|
|
|
|
After the wizard creates the skeleton code, make an addition to the code for the MouseDown and MouseUp events. Because you want your custom button to behave similarly to a standard command button, change the appearance of the button as it is "pressed." You do so by drawing black lines along the top and left edges of the button when the MouseDown event is fired and by redrawing the white lines along those edges when the MouseUp event is fired. This is coded by setting the Boolean variable bMouseDown and then running the code in the UserControl's Paint event. After you make the additions to these two events, the event code for the ColorBtn control should look like the code in Listing 14.7. |
|
|
|
|
|
|
|
|
Listing 14.7 COLORBTN.ZIPEvent Code Defined by the Wizard and Enhanced by You |
|
|
|
|
|
|
|
|
Private Sub UserControl_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
bMouseDown = True
UserControl_Paint
RaiseEvent MouseDown(Button, Shift, X, Y)
End Sub
Private Sub UserControl_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
bMouseDown = False
UserControl_Paint
RaiseEvent MouseUp(Button, Shift, X, Y)
End Sub |
|
|
|
|
|
|
|
|
|
Do not confuse the events discussed here with the events of the ColorBtn control, as seen from the user's perspective. The code in Listing 14.7 executes when the UserControl object receives mouse events. The last statement, RaiseEvent, fires the corresponding event in the ColorBtn control, executing any code the user may have placed there.  |
|
|
|
|
|
|
|
|
|
|
Figure 14.19 shows the pressed state of the ColorBtn control. |
|
|
|
|
|
|
|
|
Creating Property Pages for the Button |
|
|
|
|
|
|
|
|
The final task you will perform for the design of the Color Button control is to create the Property Pages so that the user can set the properties of the control easily. Use the Property Page Wizard to create the pages (refer to the section "Using the Property Pages Wizard" earlier in the chapter), and follow these steps: |
|
|
|
|
|